//
//  CHComposeButton.swift
//  status
//
//  Created by 彳亍 on 2017/3/22.
//  Copyright © 2017年 彳亍. All rights reserved.
//

import UIKit

class CHComposeButton: UIButton {


    override init(frame: CGRect) {
        super.init(frame: frame)
        // 设置
        setup()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    /// 设置按钮
    private func setup(){
        setImage(UIImage(named:"tabbar_compose_icon_add"), for: UIControlState.normal)
        setImage(UIImage(named:"tabbar_compose_icon_add_highlighted"), for: UIControlState.highlighted)
        setBackgroundImage(UIImage(named:"tabbar_compose_button"), for: UIControlState.normal)
        setBackgroundImage(UIImage(named:"tabbar_compose_button_highlighted"), for: UIControlState.highlighted)
        sizeToFit()
        addTarget(self, action: #selector(composeStatus), for: UIControlEvents.touchUpInside)
    }
    
    /// 撰写微博
    @objc private func composeStatus() {
        // 1.获取根控制器
        guard let rootVC = UIApplication.ch_rootController else {
            return
        }
        // 2.弹出控制器
        rootVC.present(CHComposeController(), animated: true, completion: nil)
    }
    
}

